{% extends 'manage/manageBase.html' %}

{% block script %}
    {{ super() }}

    <script>
        var id = document.location.pathname.split('/')[3];
        //JavaScript代码区域
        layui.use(['form', 'laydate'], function () {
            var form = layui.form
                , laydate = layui.laydate;
            // 时间选择框
            laydate.render({
                elem: '#gettime' //指定元素
            });

            $.ajax({
                url: "/manage/gpdApi/" + id,
                type: "get",
                async: true,
                dataType: "json",
                success: function (data) {
                    if (data.code == 10000) {
                        form.val('example', data.data[0]);   // 后台传递数据，直接渲染编辑页面
                    }
                }
            });
            //监听提交
            form.on('submit(demo1)', function (data) {
                $.ajax({
                    url: "/manage/gpdApi/" + id,
                    type: "put",
                    contentType: "application/json",
                    data: JSON.stringify(data.field),
                    success: function (data) {
                        if (data.code == 10000) {
                            layer.msg('修改成功, 2秒后将返回首页', {'icon': 1});
                            returnManageIndex()
                        } else {
                            layer.msg('修改失败, 原因: 未知', {'icon': 2})
                        }
                    }
                })
                {# layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                }) #}
                return false;
            });


        });
    </script>


{% endblock %}